package com.aioething.iot.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.aioething.iot.beans.Node;
import com.aioething.iot.dao.ProductDao;
import com.aioething.iot.model.Product;
import com.aioething.iot.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProductService implements IProductService {
    @Autowired
    private ProductDao productDao;

    @Override
    public List<Node> selector() {
        List<Product> ps = productDao.selectAll();
        List<Node> nodes = new ArrayList<>();
        if (ObjectUtil.isNotEmpty(ps)) {
            ps.forEach(p->nodes.add(new Node(p.getProductId(), p.getProductName())));
        }
        return nodes;
    }
}
